{__NOLAYOUT__}<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="__PUBLIC__/statics/style/home/wiki-view.css"/>
    <script type="text/javascript" src="__PUBLIC__/statics/script/jquery-1.11.0.js"></script>
    <!-- Highlight -->
    <link rel="stylesheet" href="__PUBLIC__/resource/script/highlight/styles/default.css">
    <script src="__PUBLIC__/resource/script/highlight/highlight.pack.js"></script>
    <script>
        hljs.configure({
            //classPrefix: ''
        });
        hljs.initHighlightingOnLoad();
    </script>
    <script src="__PUBLIC__/statics/script/library/function.js"></script>
    <base target="_blank"/>
</head>
<body class="page_resource">
<div class="main_hd"><h2 id="title"></h2></div>
<div class="main_bd">
    <div class="article_box">
        <div class="inner">
            <div class="news_content">
                <article class="post">
                    <div class="section" id="content"></div>
                </article>
            </div>
        </div>
    </div>
</div>
<!-- 从数据库中取出 -->
<div id="data_title" style="display:none">{$title}</div>
<div id="data_content" style="display:none">{$content}</div>
<!-- 取出缓存预览数据 -->
<div id="cache_title" style="display:none">{$cache_title}</div>
<div id="cache_content" style="display:none">{$cache_content}</div>
<script>
    $(function() {
        var title = '', content = '';
        if(window.opener) {
            title = window.opener.document.getElementById('title').value;
            content = window.opener.document.getElementById('content_area').value;
            content = content.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>').replace('&quot;','"');
            markdown_view(title, content);
        }
        else {
            //从cookie中取出 （因cookie字符长度限制，此方法不可取）
            //title = getCookie('preview_title');
            //content = getCookie('preview_content');
            //从缓存数据中取出
            title = $('#cache_title').html();
            content = $('#cache_content').html();
            title = title ? decodeURIComponent(decodeURIComponent(title)) : '';
            content = content ? decodeURIComponent(decodeURIComponent(content)) : '';
            if(content) {
                content = content.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>').replace('&quot;','"');
                content = content.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>').replace('&quot;','"');
            }
            if(!title || !content) {
                title = $('#data_title').html();
                content = $('#data_content').html();
            }
            markdown_view(title, content);

        }
    });
    //markdown生成预览
    function markdown_view(title, content) {
        var url = "{:U('markdown')}";
        $.ajax({
            url: url,
            data: {content:content, title:title},
            type: 'POST',
            cache: false,
            dataType: "json",
            success: function (d) {
                $('#title').html(d.title);
                $('#content').html(d.content);
                $('pre code').each(function(i, block) {
                    hljs.highlightBlock(block);
                });
            }
        });
    }
</script>
</body>
</html>
